<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//查询医保自费比
	String yydm =  input.getDesc("yydm","01");//医院代码	
	String ksdm = input.getDesc("ksdm","-1"); //传入科室代码代表该科室主任
	String date = input.getDesc("start_date","2018-01-11");//开始时间
	String endDa = input.getDesc("end_date","2018-01-11");//结束时间

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";
	//返回参数
	DecimalFormat df = new DecimalFormat("######0.00"); 
	Message msg = new Message();
	//当前使用数量
	double currentCount = 0;
	String sumCount = "";
	String sqlWhere = "";
	String hql4Where = " ";
	if(!ksdm.equals("-1")){
		sqlWhere += " and a.ksdm in(" + ksdm + ")";
		
	}
	if(!yydm.equals("-1"))
	sqlWhere += " and a.ksdm in (select id  from his_dept where yydm ='"+yydm+"') " ;
	//在院的医保人数
	String hql3 = "select new map(count(a) as count ) from ZY_BRSYK a where a.ybdm != '101' and brzt !=9 and rqrq != '' and cwdm !='' and cwdm is not null and (( cyrq >= '" + endDate + "' and rqrq <= '" + endDate + "' ) or (cyrq is null and rqrq <= '" + endDate + "')) "+ sqlWhere +"  order by count(a) desc";
	List<Map> result3 = QBuilder.db("basedb").queryHql(hql3);
	//在院的非医保人数
	String hql4 = "select new map(count(a) as count ) from ZY_BRSYK a where a.ybdm = '101' and brzt !=9 and rqrq != '' and cwdm !='' and cwdm is not null and (( cyrq >= '" + endDate + "' and rqrq <= '" + endDate + "' ) or (cyrq is null and rqrq <= '" + endDate + "')) "+ sqlWhere +" order by count(a) desc";
	List<Map> result4 = QBuilder.db("basedb").queryHql(hql4);
	
	int ybNum  = result3.size() > 0 && result3.get(0).get("count") != null ? Integer.parseInt(result3.get(0).get("count").toString()) : 0;
	
	int nybNum  = result4.size() > 0 && result4.get(0).get("count") != null ?  Integer.parseInt(result4.get(0).get("count").toString()) : 1;
	
	sumCount = ybNum + ":" + nybNum;
	
	double num1 = ybNum;
	double num2 = nybNum;
	
	Map<String,Object> m2 = new HashMap<String,Object>();
	m2.put("sumCount1",sumCount);
	m2.put("sumCount",df.format(num1/num2));
	
	Map<String,Object> m1 = new HashMap<String,Object>();
	m1.put("data",m2);
	msg.put("errcode",0);
	msg.put("ybzfb",m1);

	
	
	
	out.println(msg);
%>